How to list all tables in a schema having specific column in oracle SQL?
How to list all tables in a schema having specific column in oracle SQL?
29117-Jul-2023
Updated on 18-Jul-2023
Home / DeveloperSection / Forums / How to list all tables in a schema having specific column in oracle SQL?
How to list all tables in a schema having specific column in oracle SQL?
Aryan Kumar
18-Jul-2023Sure, here is how you can list all tables in a schema having specific column in Oracle SQL:
SQL
This query will first select all tables from the
user_tables
view. Theuser_tables
view is a data dictionary view that contains information about all of the tables in the schema that the user is currently logged in to.The next part of the query uses the
EXISTS
clause to check if each table in theuser_tables
view has the specified column. TheEXISTS
clause takes a subquery as its argument. The subquery in this case selects all columns from theuser_tab_cols
view where the table name is equal to the table name in theuser_tables
view and the column name is equal to the specified column.If the subquery returns any rows, then the
EXISTS
clause will returnTRUE
. This means that the table in theuser_tables
view has the specified column.The final part of the query selects the
table_name
column from theuser_tables
view for all tables that have the specified column.To run this query, you will need to connect to the Oracle database using a tool like SQLPlus. Once you are connected, you can run the query by typing it into the SQLPlus prompt.
For example, to run the query above, you would type the following into the SQL*Plus prompt:
SQL
This would return a list of all tables in the schema that the user is currently logged in to that have the specified column.